﻿using System;
using System.Collections.Generic;

namespace Cms.Domain.Comparers
{
    public class MediaFileComparer : IComparer<MediaFile>
    {
        private readonly MediaSortMode _mode;
        private readonly SortDirection _sortDirection;

        public MediaFileComparer(SortDirection sortDirection, MediaSortMode mode)
        {
            _sortDirection = sortDirection;
            _mode = mode;
        }

        #region IComparer<MediaFile> Members

        public int Compare(MediaFile x, MediaFile y)
        {
            int result = 0;
            switch (_mode)
            {
                case MediaSortMode.SortKey:
                    result = string.Compare(x.SortKey, y.SortKey);
                    break;
                case MediaSortMode.UploadedTimestamp:
                    result = DateTime.Compare(x.UploadedTimestamp, y.UploadedTimestamp);
                    break;
            }
            return _sortDirection == SortDirection.Ascending ? result : result * -1;
        }

        #endregion
    }
}